package logic

import (
	"activity_srv/activity"
	"activity_srv/internal/dao"
	"activity_srv/internal/svc"
	"context"
	"go.uber.org/zap"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserDistributionInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserDistributionInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserDistributionInfoLogic {
	return &GetUserDistributionInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 获取个人分销信息
func (l *GetUserDistributionInfoLogic) GetUserDistributionInfo(in *activity.GetUserDistributionInfoRequest) (*activity.GetUserDistributionInfoResponse, error) {
	//业务逻辑
	distribution, err := dao.GetUserDistributionInfo(in)
	if err != nil {
		pkg.Error("获取个人分销信息失败", zap.Error(err))
		return nil, err
	}
	pkg.Info("获取个人分销信息成功", zap.Any("distribution", distribution))
	return &activity.GetUserDistributionInfoResponse{
		Id:          distribution.Id,
		UserId:      distribution.UserId,
		TotalIncome: distribution.TotalIncome,
		Available:   distribution.Available,
		Frozen:      distribution.Frozen,
		Commission:  distribution.Commission,
	}, nil
}
